class Employee {
    Integer employeeId//
    String firstName//
    String lastName//
    Date dob//
    String title//
    Double salary//
    String email//
    String street//
    String city
    Integer zipCode
    Area hiredBy
    Integer mode =1 //default mode is sandbox mode
    Access access
    
   // Boolean admin//
    Float percentageWork = 100.0//

    static hasMany = [loaner : Bwhoa, worksIn : Whoa]

    static Integer workingHoursBellow = 1732
    static Integer workingHoursOver = 1700

    static Integer fortyYears = 40*365+10

    Integer getWorkingHoursPerYear() {
        boolean isOverForty = false
        Date today = new Date()
        if (dob != null && today.minus(dob) >= fortyYears) {
            isOverForty = true
        }
        if (isOverForty) {
            return percentageWork * workingHoursOver / 100
        } else {
            return percentageWork * workingHoursBellow / 100
        }
    }

    static transients = ['workingHoursPerYear']
    static belongsTo = Area
    
    static constraints = {
        //personal informations
        firstName(size:2..20,matches:"[a-öA-Ö ]+",blank:false)
        lastName(size:2..20,matches:"[a-öA-Ö ]+",blank:false)
        street(size:2..20,matches:"[a-öA-Ö0-9 ]+",blank:false)
        city(size:2..20,matches:"[a-öA-Ö ]+",blank:false)
        zipCode(min:10000,max:99999,blank:false)
        dob(max:new Date())
        email(size:5..50,email:true,blank:false)
        hiredBy(nullable:true)
        access(nullable:true)
        //professional informations
        title(size:1..20,blank:false)
        salary(matches:"[0-9., ]+",min:0d,max:999999d,blank:false)
        percentageWork(min:0f,max:100f)
        employeeId(blank:false)
    }
    public List listOfHours(){
        Date d = new Date();
        ArrayList l =  new ArrayList();
        for(Whoa a in worksIn){
            if(a?.year == d.getYear()){
                l.add(a);
            }
        }
        return l;
    }
    
    String toString(){"${this.firstName} ${this.lastName} "}
}
